const MyResponseModel = require('../model/MyResponseModel')

// 登录验证的中间件

async function loginCheck(ctx, next) {
  const session = ctx.session || {}
  const userInfo = session.userInfo
  if (userInfo && userInfo.username) {
    // 登录验证通过
    await next()
    return
  }
  // 登录验证失败
  const responseModel = new MyResponseModel()
  responseModel.ok = false
  responseModel.message = '用户尚未登录'
  responseModel.sys_message = 'loginCheck中间件校验不通过'
  ctx.status = 500
  ctx.body = responseModel
}

module.exports = loginCheck
